PageSpinner Database Publishing Kit


By using PageSpinner and AppleScript you can now publish web pages with data from databases on the web. This Database Publishing Kit does not support connections to online databases, the pages are static once they have been generated. This makes it possible to publish contents on e.g., Unix-based servers while maintaining the data on your Mac.

Here is a description of how you can use and modify the included samples to publish your own databases.

To publish data from a database the following items are used:

You can read more about these items below. This kit contains PageSpinner templates, sample scripts and databases for FileMaker Pro, HyperCard, and 4D Server. The examples are located in the folder named "Database Publishing" in PageSpinner's Documentation folder.

Note that the scripts are provided "AS IS", and that Optima System doesn't have resources to provide help or support for using and learning AppleScript. To find out more about AppleScript see the AppleScript Documentation in the AppleScript Documentation folder.

The following procedure is used to create the web page/pages that contains the content(s) from the database:

  1. Open your database in the database application
  2. Launch PageSpinner
  3. Launch the AppleScript with Script Editor
  4. Optionally specify the path to the templates in Script Editor
  5. Run the AppleScript by clicking on the Check button
  6. The script creates a new page in PageSpinner based upon a List template
  7. For every record in the database:
    • The script retrieves data from specified fields in the database
    • The script inserts the data in the placeholders in PageSpinner's Record template file
    • The HTML text from the template that now also contains the record contents are inserted at the end of the page created from the List template
    • The scripts remember the link or anchor name of the record
  8. The script inserts an index, consisting of a list of links to all records in the PageSpinner page created from the List template


An AppleScript created and edited in Script Editor

Script EditorAppleScripts are usually written with the application Script Editor. This application is included with the system software. It may have another name in non-U.S. systems.

Three scripts that show how to publish a database are included with PageSpinner. You may need to recompile the script and maybe change some keywords depending upon the AppleScript dialect used in your system.

These scripts work with an example database that contains records with information about products (actually Macintosh computers).

The single list example is by default set to use HyperCard Player with the data in the file named "Products HyperCard", and the multi-page and table examples are set to use FileMaker Pro with the data in the file named "Products FileMaker Pro".

Script IconDatabase List Demo Script creates a single file containing all records.

Script IconDatabase Table Demo Script creates a a file with a table containing all records.

Script IconDatabase Multi-Page Demo Script creates an index file and a single page for each record, where the record pages contain links to the next and previous record.

The colors and layout of the pages can easily be changed by modifying the PageSpinner template files.

The scripts are divided into three sections:

1. Preference Section that contains variable defining:

Before running the scripts on your system you need to change the path to the PageSpinner template files, so the script can find them.

You will also need to edit the contents in this section of the script when you want to use another database/table with other field names.

2. The Record Processing Section

The second section of the AppleScript is used to get values from the database and tell PageSpinner to insert these into the Record template that has been designed in PageSpinner. The Record template contains placeholders that indicate where the contents from a field should be placed. The script uses the following commands in the loop that processes each field:

repeat with fieldNameIndex in theFields 
  -- For every field specified above
			
  tell DB_Access
    set theData to GetField(fieldNameIndex, currentRec) as text
  end tell
			
  tell application "PageSpinner"
    set search string to "$" & fieldNameIndex & "$"
    set replace string to theData
    replace all
  end tell
			
end repeat -- For every field

This part of the script doesn't need to know which database application to use or how to access a record, it just calls GetField in the DB_Access part that implements the functions . This makes it possible to use the same script to access different database applications.

After all records has been processed the script inserts a list of links to all records that has been processed.

You will only need to edit the contents in this section of the script when you need to process the records of the database in a different way.

3. The DB_Access Section

The third section of the script is used for communicating with the database application. This part is in the form of a script module named DB_Access, at the end of the script. The module is accessed via the two following functions:

GetNumRecords()
GetField(fieldName, recordIndex)

The DB_Access script is at the end of the sample script, and is by default set to use FileMaker Pro or HyperCard Player.

Keeping the script code inside this module makes it possible to hide the details of a database application's specific implementation. This makes it easier to have a generic script that can access any of the supported databases.

The current implementation of the DB_Access module does not support relational databases. That is, it will only access fields in a single table, unless the database application handles a 1-to-1 or Many-to-1 relationship automatically.

The DB_Access script module contains commands for:

You will need to change the contents in the Script DB_Access section of the script when you want to switch to another database application. Remove the comments "--" before the lines that contains the commands for the database you want to use, and add comments before the 2 lines of the currently active commands, such as:

tell application "HyperCard Player"
  set nRecs to (get count of card)

that are used by default in the single list scripts. You'll need to change both the lines in GetNumRecords() and in the GetField() functions.


A database created and maintained with a database application

PageSpinner includes modular scripts for accessing contents from FileMaker Pro 3.0 (or later), HyperCard 2.3.5 (or later) or 4D Server (using 4D AppleScript). There are sample databases included for these applications. Use the application of your choice and the supplied database when working with the sample AppleScript.

You will need to change the contents in the Script DB_Access section of the script when you want to use another database application. You will also need to edit the contents in script's definition section to match the database and fields that should be published.


Two template files created and edited in PageSpinner

Finally, you will need to create two PageSpinner files that are used as templates; one file should contain the HTML that is used for presenting the fields from a record, and the other one is to be used as the file that will contain the index of the records.

You can take a look at the included sample files used in the List Example using your browser:

PageSpinner Stationery Icon Record_Stationery.html
PageSpinner Stationery Icon List_Stationery.html

but to see all the information in these files you should open them with PageSpinner.

The Record template contains the text $fieldname$ for every field with name fieldname that should be inserted from the database. The $...$ serves as a placeholder and will be replaced by the actual values from the database. See the AppleScript example above.

The List Template contains two special placeholders, one to mark the place where the list of links should be placed and one to specify where the actual records should be inserted.

Note: It is very important that these files are saved as stationery files, otherwise the placeholders will be overwritten with data from the database.

Tip: Select a file and use the File : Get Info menu item in Finder to access the information window where the Stationery check box can be found. It is possible to keep the Information window open while you are working with a file.

Last updated: 6/10/97
© 1995-1997 Optima System.